home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / prcgntn1.lha / Precognition / source / CheckBox.c < prev    next >
C/C++ Source or Header  |  1992-12-23  |  6KB  |  263 lines

  1. #include <stdio.h>
  2. #include "CheckBox.h"
  3. #include "CheckBoxClass.h"
  4. #include "Precognition_utils.h"
  5. #include "minmax.h"
  6. #include "AmigaMem.h"
  7. #include <proto/graphics.h>
  8. #include <proto/intuition.h>
  9. #include <proto/exec.h>
  10.  
  11. typedef struct CheckInfo
  12.    {
  13.       Border CheckMark;
  14.       BOOL   Selected;
  15.    } CheckInfo;
  16.  
  17.  
  18.  
  19. WORD CheckBox_CheckMarkPoints[] = { 16,3, 9,10, 6,10, 6,6, 7,6, 7,10,
  20.          14,3, 15,3, 8,10, 8,5, 4,5 };
  21.  
  22.  
  23.  
  24.  
  25. void CheckBox_CleanUp( CheckBox *self )
  26. {
  27.    Afree( self->g.SpecialInfo );
  28.    self->g.SpecialInfo = NULL;
  29. }
  30.  
  31.  
  32. tPoint CheckBox_FixedSize = { 22, 14 };
  33.  
  34. tPoint CheckBox_AskSize( CheckBox *self,
  35.                          PIXELS    Width,
  36.                          PIXELS    Height )
  37. {
  38.    return CheckBox_FixedSize;
  39. }
  40.  
  41.  
  42.  
  43. USHORT CheckBox_ClaimEvent( CheckBox   *self,
  44.                             IntuiMessage  *event )
  45. {
  46.    USHORT response = 0;
  47.  
  48.    switch (event->Class)
  49.    {
  50.       case REFRESHWINDOW:
  51.          response = RESPONDED;
  52.          break;
  53.  
  54.       case GADGETUP:
  55.          if (event->IAddress == (void*) &self->g)
  56.          {
  57.             response = RESPONDED | CONSUMED_EVENT | CHANGED_STATE;
  58.          }
  59.          break;
  60.    }
  61.  
  62.    return response;
  63. }
  64.  
  65.  
  66. LONG CheckBox_Value( CheckBox *self )
  67. {
  68.    CheckInfo *info;
  69.  
  70.    info = (CheckInfo *) self->g.SpecialInfo;
  71.  
  72.    return (LONG) info->Selected;
  73. }
  74.  
  75.  
  76. LONG CheckBox_SetValue( CheckBox *self,
  77.                             LONG      selection )
  78. {
  79.    CheckInfo *info;
  80.  
  81.    info = (CheckInfo *) self->g.SpecialInfo;
  82.  
  83.    info->Selected = selection;
  84.  
  85.    if (selection)
  86.    {
  87.       Forbid();
  88.       self->BoxBorder->BottomRight.NextBorder = &info->CheckMark;
  89.       Permit();
  90.    }
  91.    else
  92.    {
  93.       Forbid();
  94.       self->BoxBorder->BottomRight.NextBorder = NULL;
  95.       Permit();
  96.    }
  97.  
  98.    return (LONG) info->Selected;
  99. }
  100.  
  101. void CheckBox_Render( CheckBox *self,
  102.                       RastPort *RPort )
  103. {
  104.    PIXELS xmin, xmax, ymin, ymax;
  105.  
  106.    xmin = self->Location.x + 2;
  107.    ymin = self->Location.y + 2;
  108.    xmax = xmin + self->Size.x - 4;
  109.    ymax = ymin + self->Size.y - 4;
  110.    SetAPen( RPort, self->Pens.BackPen );
  111.    SetDrMd( RPort, JAM1 );
  112.    RectFill( RPort, xmin, ymin, xmax, ymax );
  113.  
  114.    EmbossedGadget_Render( self, RPort );
  115. }
  116.  
  117.  
  118. USHORT CheckBox_Respond( CheckBox     *self,
  119.                          IntuiMessage *event )
  120. {
  121.    CheckInfo *info;
  122.    USHORT     response = 0;
  123.    Window    *window;
  124.    USHORT     selection;
  125.  
  126.    switch (event->Class)
  127.    {
  128.       case REFRESHWINDOW:
  129.          response = RESPONDED;
  130.          break;
  131.  
  132.       case GADGETUP:
  133.          if (event->IAddress == (void*) &self->g)
  134.          {
  135.             window = event->IDCMPWindow;
  136.  
  137.             info      = (CheckInfo *) self->g.SpecialInfo;
  138.             selection = ! info->Selected;
  139.  
  140.             SetValue( self, selection );
  141.             Render( self, window->RPort );
  142.  
  143.             response = RESPONDED | CONSUMED_EVENT | CHANGED_STATE;
  144.          }
  145.          break;
  146.  
  147.    }
  148.  
  149.    return response;
  150.  
  151.  
  152. }
  153.  
  154. #ifdef BUILDER
  155. #include "BuilderMethods.h"
  156. #include "GraphicObject_Builder.h"
  157. #include "CheckBox_Builder.h"
  158. #include "Checkbox_coder.h"
  159.  
  160. struct BuilderMethods CheckBox_bm;
  161. #endif
  162.  
  163. BOOL CheckBox_elaborated = FALSE;
  164.  
  165. struct ValuatorClass CheckBox_Class;
  166.  
  167. void CheckBoxClass_Init( struct ValuatorClass *class )
  168. {
  169.    BoolGadgetClass_Init( class );
  170.    class->isa         = BoolGadgetClass();
  171.    class->ClassName   = "CheckBox";
  172.  
  173. /* -------- Commented-out methods are inherited ----------------*/
  174.    class->CleanUp     = CheckBox_CleanUp;
  175. /*   class->Location    = CheckBox_Location;*/
  176. /*   class->SetLocation = CheckBox_SetLocation;*/
  177. /*   class->Size        = CheckBox_Size;*/
  178. /*   class->SetSize     = CheckBox_SetSize;*/
  179.    class->AskSize     = CheckBox_AskSize;
  180.    class->SizeFlags  = GraphicObject_SizeFlagsNone;
  181.    class->Render      = CheckBox_Render;
  182. /*   class->FirstGadget = CheckBox_FirstGadget;*/
  183. /*   class->nGadgets    = CheckBox_nGadgets;*/
  184. /*   class->IDCMPFlags  = CheckBox_IDCMPFlags;*/
  185.    class->ClaimEvent  = CheckBox_ClaimEvent;
  186.    class->Respond     = CheckBox_Respond;
  187. /*   class->EnableIactor      = CheckBox_EnableIactor;*/
  188. /*   class->isEnabled   = CheckBox_isEnabled;*/
  189. /*   class->Activate    = NULL;*/
  190. /*   class->isActive    = NULL;*/
  191.    class->Value     = CheckBox_Value;
  192.    class->SetValue  = CheckBox_SetValue;
  193.  
  194. #ifdef BUILDER
  195.    class->BuilderMethods = &CheckBox_bm;
  196.    go_InitBuilderMethods( &CheckBox_bm );
  197.    CheckBox_bm.New       = CheckBox_New;
  198.    CheckBox_bm.PropEdit  = CheckBox_PropEdit;
  199.    CheckBox_bm.WriteCode = CheckBox_WriteCode;
  200. #endif
  201.  
  202. }
  203.  
  204.  
  205. struct ValuatorClass *CheckBoxClass( void )
  206. {
  207.    if (! CheckBox_elaborated)
  208.    {
  209.       CheckBoxClass_Init( &CheckBox_Class );
  210.       CheckBox_elaborated = TRUE;
  211.    }
  212.  
  213.    return &CheckBox_Class;
  214. }
  215.  
  216.  
  217. void CheckBox_Init( CheckBox *self,
  218.                     PIXELS      LeftEdge,
  219.                     PIXELS      TopEdge,
  220.                     pcg_3DPens  Pens,
  221.                     char       *Label,
  222.                     BOOL        Selected )
  223. {
  224.    tPoint     size;
  225.    CheckInfo *info;
  226.    AlignInfo  ainfo;
  227.  
  228. /*DUMPWAIT("CheckBox_Init\n");*/
  229.  
  230.    Interactor_Init(self);
  231.  
  232.    self->isa  = CheckBoxClass();
  233.    size       = AskSize( self, 0, 0 );
  234.  
  235.  
  236.    BoolGadget_Init( self, LeftEdge, TopEdge, size.x, size.y,
  237.                         Pens, Label );
  238.    
  239.    self->isa     = CheckBoxClass();
  240.    self->g.Flags = GADGHCOMP;
  241.  
  242.    ainfo = TextAlignment( self );
  243.    SetTextAlignment( self, tx_RIGHT | tx_YCENTER | tx_OUTSIDE,
  244.       ainfo.Xpad, ainfo.Ypad );
  245.  
  246.    info = (CheckInfo *) Acalloc( 1, sizeof(CheckInfo) );
  247.    info->Selected         = Selected;
  248.  
  249.    info->CheckMark.LeftEdge   = 0;
  250.    info->CheckMark.TopEdge    = 0;
  251.    info->CheckMark.FrontPen   = Pens.FrontPen;
  252.    info->CheckMark.BackPen    = Pens.BackPen;
  253.    info->CheckMark.DrawMode   = JAM1;
  254.    info->CheckMark.Count      = 11;
  255.    info->CheckMark.XY         = CheckBox_CheckMarkPoints;
  256.    info->CheckMark.NextBorder = NULL;
  257.    self->g.SpecialInfo        = (APTR) info;
  258.  
  259.    SetValue( self, (USHORT) Selected );
  260.  
  261. /*DUMPWAIT("end Checkbox_Init\n");*/
  262. }
  263.